package com.example.footballsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.footballsystem.entity.News;
import com.example.footballsystem.entity.Post;
import org.apache.ibatis.annotations.*;

import java.sql.Timestamp;
import java.util.List;

@Mapper
public interface PostMapper extends BaseMapper<Post>{
    @Insert("insert into schoolnews (imageLink, title, time, content, newID,createdate,userAccount,isLike,likeNum,commentNum) value (#{imagelink},#{title},#{time},#{content},#{newID},#{createDate},#{userAccount},0,0,0)")
    public Boolean addNew(Post news);
    @Select("select * from schoolnews where content like #{info}")
    public List<Post> searchByContent(String info);
    @Select("select * from schoolnews where title like #{info}")
    public List<Post> searchByTitle(String info);
    @Select("select * from schoolnews where newID=#{info}")
    public Post searchByNewID(int info);
    @Update("update schoolnews set createdate=#{create_date} where newID=#{newID}")
    public Boolean updateCreate_date(Timestamp create_date,int newID);
    @Delete("delete from schoolnews where newID=#{newID}")
    public Boolean deleteNew(int newID);
    @Select("select * from schoolnews")
    public List<Post> getAllNews();
    @Select("select COUNT(newID) from schoolnews group by userAccount")
    public List<Integer> countNews();
    @Select("select COUNT(*) from schoolnews")
    public Integer count();
    @Select("select MAX(newID) from schoolnews")
    public Integer maxNewID();
    @Update("update schoolnews set likeNum=#{num} where newID=#{newID}")
    public Boolean updateLikeNum(int newID,int num);
    @Update("update schoolnews set commentNum=commentNum+1 where newID=#{newID}")
    public Boolean updateCommentNum(int newID);
}
